#ifndef TS7260IO_H
#define TS7260IO_H

#include<unistd.h>
#include<sys/types.h>
#include<sys/mman.h>
#include<stdio.h>
#include<fcntl.h>
#include <assert.h>

#include "IO.h"

#define SYSCONBASE      0x80930000
#define DEVICE_CFG      (0x80 / sizeof(unsigned int))
#define SFTWR_LCK       (0xC0 / sizeof(unsigned int))


/*
#define PA 0x00
#define PB 0x04
#define PC 0x08
#define PE 0x20
#define PF 0x30
#define PH 0x40
*/
//{0x00, 0x10, 0x04, 0x14, 0x08, 0x18, 0x20, 0x24, 0x30, 0x34, 0x40, 0x44};
//wrapper class for TS7260 linux board I/O


class TS7260IO
{
      public:
             TS7260IO();
             ~TS7260IO();
             
             typedef unsigned char uc;
             void reportAllIO(unsigned char io[12]);
             void printAllIO();

             unsigned char read(unsigned char port);
             unsigned char write(unsigned char port);
             
            // setoutput( unsigned char bit);
            
            //for wrapped IO
                         IO        *PA, //LCD Header; pins have series resistors (5V 'tolerant') 
                                   *PB, //DIO1 Header; bits 0-7
                                   *PC, //DIO1 Header pin 4 (port c bit 0 only) "r w m cycles only???"
                                   *PE, //No Header, on board LEDS only(bit 0 grn LED, bit 1 red LED; active high)
                                   *PF, //DIO1 Header pin 8(DIO_8:  port F bit 1 only) protect other bits!
                                   *PH, //LCDHeader; LCD_EN, LCD_RS, LCD_WR (bits 3 to 5 only) protect other bits!
                                        *PC104_8, //PC104 8 bit IO base 0x11e0_0000 to 11E0_03FF            
                                         *GPIOBDB;//, *xdioDR, *xdioDIR, *xdiocfg, *xdioirq;
             
      private:
              //array of addresses corresponding to IO registers+
            
     
            //volatile unsigned int *PEDR, *PEDDR, *PBDR, *PBDDR, *GPIOBDB;//, *xdioDR, *xdioDIR, *xdiocfg, *xdioirq;
            
            //DIO2 Header xdio functionality lost due to SD card! AARGH!#@$%@!@#@%^%&%
            //DDR = 1 means it's an output
            //otherwise, DIO2 provides certain reset functions and ADC channels
           
           /*
           For non wrapped IO:
               
            volatile unsigned char *PADR, *PADDR, //LCD Header; pins have series resistors (5V 'tolerant') 
                                   *PBDR, *PBDDR, //DIO1 Header; bits 0-7
                                   *PCDR, *PCDDR, //DIO1 Header pin 4 (port c bit 0 only) "r w m cycles only???"
                                   *PEDR, *PEDDR, //No Header, on board LEDS only(bit 0 grn LED, bit 1 red LED; active high)
                                   *PFDR, *PFDDR, //DIO1 Header pin 8(DIO_8:  port F bit 1 only) protect other bits!
                                   *PHDR, *PHDDR, //LCDHeader; LCD_EN, LCD_RS, LCD_WR (bits 3 to 5 only) protect other bits!
                                   *PC104_8, //PC104 8 bit IO base 0x11e0_0000 to 11E0_03FF            
             *GPIOBDB;//, *xdioDR, *xdioDIR, *xdiocfg, *xdioirq;
            */
           
            //volatile unsigned int *syscon;
            volatile unsigned int *syscon;
            volatile unsigned char *start, *PC104_base;
            unsigned char state;//unsigned char pb;
            // char *start2;
            // char *xdioDR, *xdioDIR, *xdiocfg, *xdioirq;
            
            int fd;
              
};
#endif
